import axios from 'axios'
import { fromJS } from 'immutable'
import * as constant from './constant'
const changeHomeData = ( result ) => ({
    type: constant.CHANGE_HOME_DATA,
    remmendList: result.remmendList,
    // writerList: result.writerList,
    // articleList: result.articleList,
    boardList: result.boardList
})
const addMoreData = ( list, nextPage ) => ({
    type: constant.GET_MORE_ARTICLE,
    list: fromJS(list),
    nextPage
})
export const getHomeDate = () => {
    return (dispatch) => {
            axios.get('/api/home.json').then((res) => {
                const result = res.data.data;
                dispatch( changeHomeData(result) );
            })     
   }   
}
export const getMoreList = (page) => {
    return (dispatch) => {
            axios.get('/api/homeList.json?page' + page).then((res) => {
                const result = res.data.data;
                dispatch( addMoreData(result, page + 1) );
            }) 
            // console.log('click');    
   }   
}